Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatch event after performing a sort #178

Merged
merged 5 commits into from
Jun 4, 2024

Conversation

chrispage1
Copy link
Contributor

@chrispage1 chrispage1 commented May 31, 2024

When sorting is performed, there is currently no way to clear the cache (just one use case).

This contribution fixes this by dispatching an event.

The event dispatch allows us to listen for an event and perform whatever we need to do after the sort.

I have also added a convenience method called isFor which allows you to check directly against another string or model instance.

An example usage of this would be:

use Spatie\EloquentSortable\EloquentModelSortedEvent as SortEvent;

class SortingListener
{

    public function handle(SortEvent $event): void {
        if ($event->isFor(MyClass::class)) {
            // ToDo: flush our cache
        }
    }
}

I've also merged in the dependabot PR #176 to save you a job!

Thanks!

dependabot bot and others added 4 commits April 29, 2024 17:56
Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 1.6.0 to 2.1.0.
- [Release notes](https://github.com/dependabot/fetch-metadata/releases)
- [Commits](dependabot/fetch-metadata@v1.6.0...v2.1.0)

---
updated-dependencies:
- dependency-name: dependabot/fetch-metadata
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Added convenience helper to event
…ctions/dependabot/fetch-metadata-2.1.0' into feature/dispatch-event
@freekmurze
Copy link
Member

Nice, could you also update the readme with an example on how to use this?

@chrispage1
Copy link
Contributor Author

Nice, could you also update the readme with an example on how to use this?

Of course, I have updated the README file 👍

Chris.

@freekmurze freekmurze merged commit a8d09f5 into spatie:main Jun 4, 2024
17 checks passed
@freekmurze
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants